package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.GlueProduct;
import com.ruoyi.system.domain.dto.AdhesiveModelDto;
import com.ruoyi.system.domain.vo.AdhesiveModelVo;
import com.ruoyi.system.mapper.GlueProductMapper;
import com.ruoyi.system.service.IGlueProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 胶粘产品Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class GlueProductServiceImpl extends ServiceImpl<GlueProductMapper,GlueProduct> implements IGlueProductService
{
    @Autowired
    private GlueProductMapper glueProductMapper;

    List<String> purpose = Arrays.asList("粘接","密封","绝缘","灌封","螺纹锁固","固持");

    List<String> operatingTemperature = Arrays.asList("-20℃以下","-20-100℃","100℃以上 ");

    List<String> isHighHumiditySuitable = Arrays.asList("能","不能");

    List<String> viscosity = Arrays.asList("中低粘度（流动性液体）","高粘度（膏状体）");

    List<String> curingTime = Arrays.asList("1小时以内到达初固强度","1小时以上到达初固强度");

    List<String> curedStrength = Arrays.asList("低强度（0-3MPa）","中等强度（3-15MPa）","高强度（15MPa以上）");

    List<String> strings = Arrays.asList("金属","热塑性塑料(低表面能PP PE等)","热塑性塑料(高表面能PA ABS PC等)","热固性塑料(SMC等)","橡胶","玻璃","聚四氟乙烯");


    /**
     * 查询胶粘产品
     *
     * @param id 胶粘产品主键
     * @return 胶粘产品
     */
    @Override
    public GlueProduct selectGlueProductById(Long id)
    {
        return glueProductMapper.selectGlueProductById(id);
    }

    /**
     * 查询胶粘产品列表
     *
     * @param glueProduct 胶粘产品
     * @return 胶粘产品
     */
    @Override
    public List<GlueProduct> selectGlueProductList(GlueProduct glueProduct)
    {

        int a = operatingTemperature.indexOf(glueProduct.getTemperature());
        glueProduct.setTemperatureCode(a);


        int b = viscosity.indexOf(glueProduct.getViscosity());
        glueProduct.setViscosityCode(b);

        int c = curedStrength.indexOf(glueProduct.getStrength());
        if(c == 0){
            glueProduct.setStrength("低");
        }else if(c == 1){
            glueProduct.setStrength("中");
        }else if(c == 2){
            glueProduct.setStrength("高");
        }

        int d = curingTime.indexOf(glueProduct.getCuringTime());
        if(d == 0){
            glueProduct.setCuringTime("＜1h");
        }else if(d == 1){
            glueProduct.setCuringTime("＞1h");
        }
        return glueProductMapper.selectGlueProductList(glueProduct);
    }

    /**
     * 新增胶粘产品
     *
     * @param glueProduct 胶粘产品
     * @return 结果
     */
    @Override
    public int insertGlueProduct(GlueProduct glueProduct)
    {
        glueProduct.setCreateTime(DateUtils.getNowDate());
        glueProduct.setCreateBy(SecurityUtils.getUserId().toString());
        return glueProductMapper.insertGlueProduct(glueProduct);
    }

    /**
     * 修改胶粘产品
     *
     * @param glueProduct 胶粘产品
     * @return 结果
     */
    @Override
    public int updateGlueProduct(GlueProduct glueProduct)
    {
        glueProduct.setUpdateTime(DateUtils.getNowDate());
        return glueProductMapper.updateGlueProduct(glueProduct);
    }

    /**
     * 批量删除胶粘产品
     *
     * @param ids 需要删除的胶粘产品主键
     * @return 结果
     */
    @Override
    public int deleteGlueProductByIds(Long[] ids)
    {
        return glueProductMapper.deleteGlueProductByIds(ids);
    }

    /**
     * 删除胶粘产品信息
     *
     * @param id 胶粘产品主键
     * @return 结果
     */
    @Override
    public int deleteGlueProductById(Long id)
    {
        return glueProductMapper.deleteGlueProductById(id);
    }


//    /**
//     * 获取选型三级目录
//     * @param dto
//     * @return
//     */
//    @Override
//    public AdhesiveModelVo getModel(AdhesiveModelDto dto) {
//        AdhesiveModelVo adhesiveModelVo = new AdhesiveModelVo();
//        adhesiveModelVo.setPurpose(glueProductMapper.getPurpose(dto));
//        adhesiveModelVo.setOperatingTemperature(glueProductMapper.getOperatingTemperature(dto));
//        adhesiveModelVo.setIsHighHumiditySuitable(glueProductMapper.getIsHighHumiditySuitable(dto));
//        adhesiveModelVo.setViscosity(glueProductMapper.getViscosity(dto));
//        adhesiveModelVo.setCuredStrength(glueProductMapper.getCuredStrength(dto));
//        adhesiveModelVo.setCuringTime(glueProductMapper.getCuringTime(dto));
//        List<String> strings = Arrays.asList("金属","热塑性塑料(低表面能PP PE等)","热塑性塑料(高表面能PA ABS PC等)","热固性塑料(SMC等)","橡胶","玻璃","聚四氟乙烯");
//        adhesiveModelVo.setMaterial1(strings);
//        adhesiveModelVo.setMaterial2(strings);
//        return adhesiveModelVo;
//
//    }

    /**
     * 获取选型三级目录
     * @param dto
     * @return
     */
    @Override
    public AdhesiveModelVo getModel(AdhesiveModelDto dto) {
        AdhesiveModelVo adhesiveModelVo = new AdhesiveModelVo();


        adhesiveModelVo.setPurpose(purpose);


        adhesiveModelVo.setOperatingTemperature(operatingTemperature);

        adhesiveModelVo.setIsHighHumiditySuitable(isHighHumiditySuitable);

        adhesiveModelVo.setViscosity(viscosity);

        adhesiveModelVo.setCuredStrength(curedStrength);


        adhesiveModelVo.setCuringTime(curingTime);

        adhesiveModelVo.setMaterial1(strings);
        adhesiveModelVo.setMaterial2(strings);
        return adhesiveModelVo;
    }
}
